package parserjc;

/**
 * Automatisch generierte Klasse
 * @author Jaccie
 */

import java.util.*;
import parserjc.jaccie.*;

public class Compile extends Observable
              implements CompilerAction, Runnable {

    private String input = "";
    private Parser parser =  new Parser();
    
    private Boolean parsable = false;

    public void setInput(Object o) {
        input = (String)o;
    }

    public void run() {
        Scanner scanner =  new Scanner();
        scanner.getScannerInput().setInput(input);
        try {
            scanner.resetScanner();
            scanner.scanAll();
        } catch (Exception e) {
             update("Error while scanning: "+
                    e.toString());
        }
        update("Scanner finished.");

        SICParserInput pinput = new SICParserInput();
        Vector scannerResult = scanner.getResult();

        for (int i=0; i<scannerResult.size(); i++)
            pinput.addScannerOutput((String)
                scannerResult.elementAt(i));
        
        parsable = parser.start(pinput);
        
        update("Parser finished.");

        update("Finished.");
    }

    public Object getResult() {
        return parser.getResult();
    }

    private Observer observer = null;

    public void setObserver(Observer o) {
         observer = o;
    }

    private void update(String message) {
        if (observer != null) observer.update(this,message);
    }
    
    public Boolean parsable() {
        return parsable;
    }
    
    public SICTree getSICTree() {
        return (SICTree) getResult();
    }
}
